/**
 * Created by yuris on 22.12.14.
 */
package model.objects {
import flash.geom.Point;
import flash.geom.Point;

import model.Constants;

import model.prototypes.ShopperProto;

import org.osflash.signals.Signal;

public class ShopperData extends ShopObjectData{
    private var _path:Vector.<Point> = null;
    private var _pathPointer:int;

    private var _prevAction:String = Constants.SHOPPER_ACTION_NONE;
    private var _action:String = Constants.SHOPPER_ACTION_NONE;
    private var _actionParam:Object = null;

    private var _isActive:Boolean = false;

    private var _previousPosition:Point = null;

    public function ShopperData() {
        super (new ShopperProto());
    }



    public function set path(value:Vector.<Point>):void {
        _path = value;
        _pathPointer = 0;
    }

    public function get isActive():Boolean {
        return this._isActive;
    }

    public function set isActive(value:Boolean):void {
        this._isActive = value;
        this._updateSignal.sendSignal(Constants.OBJECT_STATUS_UPDATE_SIGNAL, this._isActive);
    }

    override public function set angle(value:int):void {
        this._angle = value;

        this._updateSignal.sendSignal(Constants.OBJECT_ANGLE_UPDATE_SIGNAL, this._angle);
    }

    public function setAction(value:String, param:Object = null):void {
        this._prevAction = this._action;
        this._action = value;
        this._actionParam = param;

        switch (this._action){
            case Constants.SHOPPER_ACTION_GO://rotate and change position data (without position signal)
                    this._previousPosition = this._position.clone();
                    this._position = this._actionParam as Point;
                    this.angle = ShopObjectData.getAngleByVector(this._position.subtract(this._previousPosition));

                break;
            case Constants.SHOPPER_ACTION_WATCH_PRODUCT:
                this.angle = ShopObjectData.getAngleByVector((this._actionParam as ShopObjectData).position.subtract(this._position));
                break;
        }
        this._updateSignal.sendSignal(Constants.OBJECT_ACTION_UPDATE_SIGNAL, {action:this._action, param:this._actionParam});
    }

    public function get prevAction():String {
        return _prevAction;
    }

    public function get path():Vector.<Point> {
        return _path;
    }

    public function get pathPointer():int {
        return _pathPointer;
    }

    public function set pathPointer(value:int):void {
        _pathPointer = value;
    }

    public function get previousPosition():Point {
        return _previousPosition;
    }
}
}
